package com.lan.mock13.shengsai.tG;

import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		while(input.hasNext()) {
			int n = input.nextInt();
			
			int[] num = new int[n];
			for (int i = 0; i < n; i ++) {
				num[i] = input.nextInt();
			}
			
			int m = input.nextInt();
			long origin = 0;
			int[] p = new int[n];
			for (int i = 0; i < m; i ++) {
				int left = input.nextInt();
				int right = input.nextInt();
				for(int j = left - 1; j < right; j ++) {
					p[j]++;
					origin += num[j];
				}
			}
			
			Arrays.sort(num);
			Arrays.sort(p);
			
			long res = 0;
			
			for (int i = 0; i < n; i ++) {
				res += (long)(num[i] * p[i]);
			}
			
			System.out.println(res - origin);
		}
		input.close();
	}
}
